package com.bistu.openlab.uofspreadsheet.xmlparse;

import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.bistu.openlab.uofspreadsheet.model.MaxRowCol;
import com.bistu.openlab.uofspreadsheet.util.TypeConvertor;
import com.bistu.openlab.uofspreadsheet.util.XmlDomHelper;

/*
 *@author xiaoguang.gao@oracle.com
 *@version 2013-5-9 
 */
public class MaxRowColParse implements IXmlParse<MaxRowCol>{
	private static MaxRowColParse parse = new MaxRowColParse();
	private MaxRowColParse(){}
	/**
	 * 
	 * @return
	 */
	public static MaxRowColParse getInstance(){
		return parse;
	}

	@Override
	public MaxRowCol readFromElement(Element root) {
		MaxRowCol max = null;
		if(root!=null){
			max = new MaxRowCol();
			//max row
			String strMaxRow = XmlDomHelper.GetAttributeValue(root, "最大行_E7E7");
			int maxRow = TypeConvertor.GetInt(strMaxRow);
			max.setMaxRow(maxRow);
			//max column
			String strMaxCol = XmlDomHelper.GetAttributeValue(root, "最大列_E7E8");
			int maxCol = TypeConvertor.GetInt(strMaxCol);
			max.setMaxCol(maxCol);
		}
		return max;
	}

	@Override
	public Element writeToElement(MaxRowCol obj) {
		if(obj==null){
			obj = new MaxRowCol();
		}
		Element root = DocumentHelper.createElement("表:最大行列_E7E6");
		root.addAttribute("最大行_E7E7", obj.getMaxRow()+"");
		root.addAttribute("最大列_E7E8", obj.getMaxCol()+"");
		return root;
	}

}
